var vue_load = new Vue({
  el: '#article-vue',
  data: {
    type: 'news',
    list: [],
		pages: {
    	pageNo: 1,
			totalPages: 1
		},
		noHas: false
  },
	methods: {
  	checkScroll: function () {
  		if (this.list.length > 0) {
        var all = document.querySelectorAll('.check-scroll');
        var last = all[all.length - 1];
        var ah = last.clientHeight / 3 + last.offsetTop;
        var lh = window.innerHeight + window.scrollY;
        return ah < lh;
			}
			return false;
    },
		loadArt: function () {
  		$.post('/article/page/' + this.pages.pageNo, {type: this.type}, function (data) {
				if (data.success) {
          vue_load.list = vue_load.list.concat(data.payload.rows);
          vue_load.pages.pageNo = data.payload.pageNum;
          vue_load.pages.totalPages = data.payload.totalPages;
				}
      });
    }
	},
	components: {
  	'article-box': {
  		props: ['art'],
			template: '#art-template'
		}
	},
	mounted: function () {
		window.onscroll = function () {
			if (vue_load.checkScroll()) {
				if (vue_load.pages.pageNo < vue_load.pages.totalPages) {
          vue_load.pages.pageNo++;
          vue_load.loadArt();
				} else {
					vue_load.noHas = true;
				}
			}
    }
  }
});